import 'package:flutter/material.dart';
import 'package:get/get.dart';

class MyAlertWidget extends StatelessWidget {
  final String title;
  final Widget? content;
  final String contentText;
  final String? confirmText;
  final String? cancelText;
  final VoidCallback? onConfirm;
  final VoidCallback? onCancel;

  const MyAlertWidget({super.key, this.title = "", this.content, this.contentText = "", this.confirmText, this.cancelText, this.onConfirm, this.onCancel});

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Center(
        child: Container(
          width: MediaQuery.of(context).size.width - 80,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(16),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Padding(
                padding: const EdgeInsets.symmetric(vertical: 12),
                child: Text(
                  title ?? "",
                  style: const TextStyle(fontSize: 16, color: Colors.black, fontWeight: FontWeight.w500),
                ),
              ),
              content ??
                  Container(
                    padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
                    child: Text(
                      contentText,
                      textAlign: TextAlign.center,
                      style: const TextStyle(color: Color(0XFF333333), fontSize: 14, fontWeight: FontWeight.w400),
                    ),
                  ),
              SizedBox(
                height: 46,
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Expanded(
                      child: TextButton(
                        onPressed: () {
                          onCancel?.call();
                          Get.back(result: false);
                        },
                        child: Text(
                          cancelText ?? "取消",
                          style: const TextStyle(color: Color(0XFF999999)),
                        ),
                      ),
                    ),
                    Expanded(
                      child: TextButton(
                        onPressed: () {
                          onConfirm?.call();
                          Get.back(result: true);
                        },
                        child: Text(
                          confirmText ?? "确定",
                          style: const TextStyle(color: Color(0XFFE4B591)),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
